﻿    /*----------------------------------------------------
 * Author : Tharinduni Udugamasuriya
 * Date : June 2014
 * GlobalVariables : To manage Global Variables
 ---------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;
using System.Data.SqlClient;
using DSPL.Contracts.Interfaces;

namespace DSPL.Contracts.Common
{
    public static class GlobalVariables
    {

        static string machineName;
        static IUnityContainer globalUnityContainer;
        static List<string> masterInsertIgnoreList;
        static List<string> masterUpdateIgnoreList;
        static List<string> masterDeleteIgnoreList;
        static List<string> masterLogIgnoreList;
        static List<string> txnHedInsIgnoreList;
        static List<string> txnDetInsIgnoreList;
        static List<string> txnHedUpdIgnoreList;
        static List<string> txnDetUpdIgnoreList;
        static List<string> txnHedLogIgnoreList;
        static List<string> txnDetLogIgnoreList;
        static string _loggedInUser = "DSPL";
        static int costCenter;
        static int location;
        
        static ICommonReadService commonReadService { get; set; }

        public static string UserName { get; set; }
        //{
        //    get { return new RegistryManager().FinUser; }
        //    set { username = new RegistryManager().FinUser; }
        //}

        public static string Password { get; set; }
        //{
        //    get { return new RegistryManager().FinPassword; }
        //    set { password = new RegistryManager().FinPassword; }
        //}

        //public static string Connectionstring
        //{
        //    get { return new RegistryManager().FinConStr; }
        //    set { connectionString = new RegistryManager().FinConStr; }
        //}


        public static string Connectionstring = ConfigurationManager.ConnectionStrings["Global"].ConnectionString;

        
        public static IUnityContainer GlobalUnityContainer
        {
            get
            {
                globalUnityContainer = new UnityContainer();
                return globalUnityContainer.LoadConfiguration("customContainer");
            }
        }

        public static string Database { get; set; }
        //{
        //    get { return new RegistryManager().FinDb; }
        //    set { database = new RegistryManager().FinDb; }
        //}

        public static string Server { get; set; }
        //{
        //    get { return new RegistryManager().FinServer; }
        //    set { server = new RegistryManager().FinServer; }
        //}

        public static string MachineName
        {
            get { return Environment.MachineName + "#" + Environment.UserName; }
            set { machineName = Environment.MachineName + "#" + Environment.UserName; }
        }

        public const string ApplicationName = "FiNAC - Global";

        public static List<string> MasterInsertIgnoreList
        {
            get
            {
                masterInsertIgnoreList = new List<string> ();
                masterInsertIgnoreList.Add("RECORDID");
                masterInsertIgnoreList.Add("PK");
                masterInsertIgnoreList.Add("TIMESTAMP_COLUMN");
                masterInsertIgnoreList.Add("ADDUSER");
                masterInsertIgnoreList.Add("ADDDATE");
                masterInsertIgnoreList.Add("ADDMACH");
                return masterInsertIgnoreList;
            }
        }

        public static List<string> MasterUpdateIgnoreList
        {
            get
            {
                masterUpdateIgnoreList = new List<string>();
                masterUpdateIgnoreList.Add("RECORDID");
                masterUpdateIgnoreList.Add("TIMESTAMP_COLUMN");
                masterUpdateIgnoreList.Add("ADDUSER");
                masterUpdateIgnoreList.Add("ADDDATE");
                masterUpdateIgnoreList.Add("ADDMACH");
                return masterUpdateIgnoreList;
            }
        }

        public static List<string> MasterDeleteIgnoreList
        {
            get 
            {
                masterDeleteIgnoreList = new List<string>();
                masterDeleteIgnoreList.Add("RECORDID");
                masterDeleteIgnoreList.Add("TIMESTAMP_COLUMN");
                masterDeleteIgnoreList.Add("ADDUSER");
                masterDeleteIgnoreList.Add("ADDDATE");
                masterDeleteIgnoreList.Add("ADDMACH");
                return masterDeleteIgnoreList; 
            }
        }

        public static List<string> MasterLogIgnoreList
        {
            get 
            {
                masterLogIgnoreList = new List<string>();
                masterLogIgnoreList.Add("RECORDID");
                masterLogIgnoreList.Add("DELUSER");
                masterLogIgnoreList.Add("TIMESTAMP_COLUMN");
                masterLogIgnoreList.Add("DELDATE");
                masterLogIgnoreList.Add("DELMACH");
                masterLogIgnoreList.Add("DELTYPE"); 
                return masterLogIgnoreList;
            }
        }

        public static List<string> TxnHedInsertIgnoreList
        {
            get
            {
                txnHedInsIgnoreList = new List<string>();
                txnHedInsIgnoreList.Add("RECORDID");
                txnHedInsIgnoreList.Add("PK");
                txnHedInsIgnoreList.Add("TIMESTAMP_COLUMN");
                txnHedInsIgnoreList.Add("ADDUSER");
                txnHedInsIgnoreList.Add("ADDDATE");
                txnHedInsIgnoreList.Add("ADDMACH");
                txnHedInsIgnoreList.Add("APPUSER");
                txnHedInsIgnoreList.Add("APPDATETIME");
                txnHedInsIgnoreList.Add("APPSTAT");
                txnHedInsIgnoreList.Add("PRTCOPY");
                return txnHedInsIgnoreList;
            }
        }

        public static List<string> TxnDetInsertIgnoreList
        {
            get
            {
                txnDetInsIgnoreList = new List<string>();
                txnDetInsIgnoreList.Add("RECORDID");
                txnDetInsIgnoreList.Add("PK");
                txnDetInsIgnoreList.Add("TIMESTAMP_COLUMN");
                return txnDetInsIgnoreList;
            }
        }

        public static List<string> TxnHedUpdateIgnoreList
        {
            get
            {
                txnHedUpdIgnoreList = new List<string>();
                txnHedUpdIgnoreList.Add("RECORDID");
                txnHedUpdIgnoreList.Add("PK");
                txnHedUpdIgnoreList.Add("TIMESTAMP_COLUMN");
                txnHedUpdIgnoreList.Add("ADDUSER");
                txnHedUpdIgnoreList.Add("ADDDATE");
                txnHedUpdIgnoreList.Add("ADDMACH");
                txnHedUpdIgnoreList.Add("APPUSER");
                txnHedUpdIgnoreList.Add("APPDATETIME");
                txnHedUpdIgnoreList.Add("APPSTAT");
                txnHedUpdIgnoreList.Add("PRTCOPY");
                return txnHedUpdIgnoreList;
            }
        }

        public static List<string> TxnDetUpdateIgnoreList
        {
            get
            {
                txnDetUpdIgnoreList = new List<string>();
                txnDetUpdIgnoreList.Add("RECORDID");
                txnDetUpdIgnoreList.Add("PK");
                txnDetUpdIgnoreList.Add("TIMESTAMP_COLUMN");
                return txnDetUpdIgnoreList;
            }
        }

        public static List<string> TxnHedLogIgnoreList
        {
            get
            {
                txnHedLogIgnoreList = new List<string>();
                txnHedLogIgnoreList.Add("RECORDID");
                txnHedLogIgnoreList.Add("DELUSER");
                txnHedLogIgnoreList.Add("TIMESTAMP_COLUMN");
                txnHedLogIgnoreList.Add("DELDATE");
                txnHedLogIgnoreList.Add("DELMACH");
                txnHedLogIgnoreList.Add("DELTYPE");
                txnHedLogIgnoreList.Add("DELREASN");
                return txnHedLogIgnoreList;
            }
        }

        public static List<string> TxnDetLogIgnoreList
        {
            get
            {
                txnDetLogIgnoreList = new List<string>();
                txnDetLogIgnoreList.Add("RECORDID");
                txnDetLogIgnoreList.Add("DELUSER");
                txnDetLogIgnoreList.Add("TIMESTAMP_COLUMN");
                txnDetLogIgnoreList.Add("DELDATE");
                txnDetLogIgnoreList.Add("DELMACH");
                txnDetLogIgnoreList.Add("DELTYPE");
                return txnDetLogIgnoreList;
            }
        }

        public static string LoggedInUser
        {
            get { return _loggedInUser; }
            set { _loggedInUser = value; }
        }

        public static string BaseCurrency
        {
            get { return ConfigurationManager.AppSettings["BaseCurrency"].ToString().Trim(); }
        }

        public static string CompanyName
        {
            get { return ConfigurationManager.AppSettings["CompanyName"].ToString().Trim(); }
        }

        public static string Address
        {
            get { return ConfigurationManager.AppSettings["Address"].ToString().Trim(); }
        }

        public static string ContactDetails
        {
            get { return ConfigurationManager.AppSettings["ContactDetails"].ToString().Trim(); }
        }

        public static string OnlineDetails
        {
            get { return ConfigurationManager.AppSettings["OnlineDetails"].ToString().Trim(); }
        }


        public static string CopyRight
        {
            get { return ConfigurationManager.AppSettings["CopyRight"].ToString().Trim(); }
        }

        public static string SystemCurrency
        {
            get { return ConfigurationManager.AppSettings["SystemCurrency"].ToString().Trim(); }
        }

        public static string VatCompanyTaxNo
        {
            get
            {
                return ConfigurationManager.AppSettings["VatCompanyTaxNo"].ToString().Trim();
            }
        }


        public static int CurValDecimalPoints
        {
            get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("CurValDecimalPoints")); }
        }

        public static int AverageRateDecimal
        {
            get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("AvgRateDecimal")); }
        }

        public static int RefNoLength { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("RefNoLength")); } }

        public static int NumberofRecodsPerPage { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("NumberofRecodsPerPage")); } }

        public static string AttachmentFolderPath { get { return ConfigurationManager.AppSettings.Get("AttachmentFolderPath").ToString().Trim(); } }

        public static string CurrencyValueFormat { get { return ConfigurationManager.AppSettings.Get("CurrencyValueFormat").ToString().Trim(); } }
        
        public static string CurrencyRateFormat { get { return ConfigurationManager.AppSettings.Get("CurrencyRateFormat").ToString().Trim(); } }
        
        public static string QtyFormat { get { return ConfigurationManager.AppSettings.Get("QtyFormat").ToString().Trim(); } }
        
        public static string AverageRateFormat { get { return ConfigurationManager.AppSettings.Get("AverageRateFormat").ToString().Trim(); } }

        public static string DiscountPerFormat { get { return ConfigurationManager.AppSettings.Get("DiscountPerFormat").ToString().Trim(); } }
       
        public static string ValueFormat { get { return ConfigurationManager.AppSettings.Get("ValueFormat").ToString().Trim(); } }

        public static int CurrencyValueDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("CurrencyValueDecimal")); } }
        
        public static int CurrencyRateDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("CurrencyRateDecimal")); } }
        
        public static int QtyDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("QtyDecimal")); } }
        
        public static int AverageRateDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("AverageRateDecimal")); } }

        public static int DiscountPerDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("DiscountPerDecimal")); } }
        
        public static int ValueDecimal { get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("ValueDecimal")); } }
        
        public static int AverageRateDecimalPoints
        {
            get
            {
                return Convert.ToInt32(ConfigurationManager.AppSettings.Get("AverageRateDecimalPoints"));
            }           
        }

        public static int UserCostCenter
        {
            get { return costCenter; }
            set { costCenter = value; }
        }

        public static int UserLocation
        {
            get { return location; }
            set { location = value; }
        }

        public static void LoadDatabaseGlobalVariables()
        {            
            IUnityContainer container = GlobalUnityContainer;
            if (container != null)
                commonReadService = container.Resolve<ICommonReadService>();

            if (commonReadService != null)
            {
                costCenter = commonReadService.GetUserWiseCostCenter();
                location = commonReadService.GetUserWiseLocation();
            }
        }
    }
}
